package utiliy

import play.api.mvc.RequestHeader
import security.access.PermissionAccess

object RequestHelper {

  def isLogin(permission:String)(implicit requestHeader: RequestHeader) = {
    //    requestHeader.session.get("accid").nonEmpty
    val access = requestHeader.session.get("admin").getOrElse("0")
    PermissionAccess.check(access, permission)
  }

  def getUid(implicit requestHeader: RequestHeader) = {
    requestHeader.session.get("accid")
  }

  def getName(implicit requestHeader: RequestHeader) = {
    requestHeader.session.get("uname")
  }

  def getSign(implicit requestHeader: RequestHeader) = {
    requestHeader.session.get("sign")
  }

  def isAdmin(implicit requestHeader: RequestHeader) = {
    //    requestHeader.session.get("admin").getOrElse("0") == "true"
    val access = requestHeader.session.get("admin").getOrElse("0")
    PermissionAccess.check(access, "admin")
  }

}
